<template>
    <div class="common-layout">
        <el-container class="full-container">
            <el-header class="main-header">
                <div class="header-left">
                    <span class="logo-icon">🐰</span>
                    爱吃兔企业项目
                </div>
                <div class="header-user">
                    <div class="user-details">
                        <span class="user-role">您的角色：{{ store.CurrentLogin.roleName }}</span>
                        <span class="user-name">{{ store.CurrentLogin.userNickName }}（{{ store.CurrentLogin.userName
                        }}）</span>
                    </div>
                    <el-tag type="info" size="small" class="role-tag">[{{ store.CurrentLogin.roleName }}]</el-tag>
                    <el-button type="danger" size="small" @click="Exit" class="logout-btn">
                        <el-icon>
                            <Close />
                        </el-icon>
                        退出登录
                    </el-button>
                </div>
            </el-header>
            <el-container class="body-container">
                <el-aside width="260px" class="main-aside">
                    <div class="sidebar-header">
                        <h3>导航菜单</h3>
                    </div>
                    <el-menu default-active="2" router class="sidebar-menu" background-color="transparent"
                        text-color="#2c3e50" active-text-color="#409EFF">
                        <el-sub-menu index="1">
                            <template #title>
                                <el-icon class="menu-icon">
                                    <Location />
                                </el-icon>
                                <span>溯源管理</span>
                            </template>
                            <el-menu-item-group>
                                <el-menu-item index="Show" class="menu-item">
                                    <el-icon>
                                        <Document />
                                    </el-icon>
                                    溯源管理-溯源详情
                                </el-menu-item>
                                <el-menu-item index="FarmShow" class="menu-item">
                                    <el-icon>
                                        <House />
                                    </el-icon>
                                    溯源管理-溯源详情-养殖信息
                                </el-menu-item>
                            </el-menu-item-group>
                        </el-sub-menu>
                    </el-menu>
                </el-aside>
                <el-main class="main-content">
                    <div class="content-wrapper">
                        <router-view></router-view>
                    </div>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { Read } from '@/components/Http/axiosHepler'
import { ElMessage } from 'element-plus';
import { Location, Close, Document, House } from '@element-plus/icons-vue';
import { useCounterStore } from "@/stores/counter"
import { useRoute, useRouter } from 'vue-router';
import router from '@/router';

const Router = useRouter();
const Route = useRoute();
const store = useCounterStore();

const Exit = () => {
    //清空用户信息
    store.CurrentLogin.userId = 0
    store.CurrentLogin.userName = ""
    store.CurrentLogin.userNickName = ""
    store.CurrentLogin.roleId = 0
    store.CurrentLogin.roleName = ""

    store.CurrentLogin.token = ""
    router.push("/")
}

const testJWT = () => {
    Read.get("/Test/health").then(res => {

    }).catch(error => {
        console.log("钩子：" + error)
    })
}

onMounted(() => {
    testJWT()
})

</script>

<style scoped>
html,
body,
#app {
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

.common-layout,
.full-container {
    width: 1000px;
    height: 100vh;
    min-height: 100vh;
    min-width: 100vw;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.full-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
    overflow: hidden;
}

.full-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="50" cy="50" r="1" fill="rgba(255,255,255,0.1)"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
    opacity: 0.3;
    pointer-events: none;
}

.body-container {
    flex: 1;
    display: flex;
    height: calc(100vh - 70px);
    width: 100%;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    color: #2c3e50;
    font-size: 1.1rem;
    height: 70px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    padding: 0 32px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    position: relative;
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    font-weight: 700;
    font-size: 1.4rem;
    letter-spacing: 1px;
    color: #2c3e50;
}

.logo-icon {
    font-size: 1.8rem;
    margin-right: 16px;
    animation: bounce 2s infinite;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-5px);
    }

    60% {
        transform: translateY(-3px);
    }
}

.header-user {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-details {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.user-role {
    font-size: 0.85rem;
    color: #7f8c8d;
    font-weight: 500;
}

.user-name {
    font-size: 0.95rem;
    color: #2c3e50;
    font-weight: 600;
}

.role-tag {
    border-radius: 16px;
    font-weight: 500;
    padding: 6px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.role-tag:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.logout-btn {
    border-radius: 12px;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.3);
    padding: 8px 16px;
    border: none;
}

.logout-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(220, 53, 69, 0.4);
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
}

.main-aside {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(15px);
    height: 100%;
    border-right: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    flex-direction: column;
    padding: 0;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.12);
    position: relative;
    z-index: 5;
}

.sidebar-header {
    padding: 28px 20px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.8) 0%, rgba(255, 255, 255, 0.4) 100%);
}

.sidebar-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    color: #2c3e50;
    text-align: center;
    letter-spacing: 1px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.sidebar-menu {
    flex: 1;
    padding: 16px 0;
}

.sidebar-menu :deep(.el-menu-item) {
    height: 52px;
    line-height: 52px;
    margin: 6px 16px;
    border-radius: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
}

.sidebar-menu :deep(.el-menu-item:hover) {
    background: rgba(64, 158, 255, 0.12);
    color: #409EFF;
    transform: translateX(6px);
    box-shadow: 0 4px 12px rgba(64, 158, 255, 0.2);
}

.sidebar-menu :deep(.el-menu-item.is-active) {
    background: linear-gradient(135deg, #409EFF 0%, #36a3f7 100%);
    color: white;
    box-shadow: 0 6px 20px rgba(64, 158, 255, 0.4);
    transform: translateX(4px);
}

.sidebar-menu :deep(.el-sub-menu__title) {
    height: 52px;
    line-height: 52px;
    margin: 6px 16px;
    border-radius: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 600;
}

.sidebar-menu :deep(.el-sub-menu__title:hover) {
    background: rgba(64, 158, 255, 0.12);
    color: #409EFF;
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(64, 158, 255, 0.2);
}

.menu-icon {
    margin-right: 10px;
    font-size: 1.2rem;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

.menu-item {
    padding-left: 52px !important;
    font-size: 0.95rem;
}

.main-content {
    height: 100%;
    width: 100%;
    overflow: auto;
    flex: 1;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(15px);
    padding: 32px;
    position: relative;
    z-index: 1;
}

.content-wrapper {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    min-height: calc(100% - 64px);
    padding: 32px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(10px);
    position: relative;
}

.content-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
    border-radius: 20px;
    pointer-events: none;
}

/* 滚动条样式 */
.main-content::-webkit-scrollbar {
    width: 10px;
}

.main-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    margin: 4px;
}

.main-content::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, rgba(64, 158, 255, 0.4) 0%, rgba(54, 163, 247, 0.4) 100%);
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.main-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, rgba(64, 158, 255, 0.6) 0%, rgba(54, 163, 247, 0.6) 100%);
    box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .header-left {
        font-size: 1.1rem;
    }

    .header-user {
        gap: 8px;
    }

    .user-details {
        display: none;
    }

    .main-aside {
        width: 200px !important;
    }
}
</style>
